﻿//===============================================================================
// Microsoft patterns & practices
// Windows Phone 7 Developer Guide
//===============================================================================
// Copyright © Microsoft Corporation.  All rights reserved.
// This code released under the terms of the 
// Microsoft patterns & practices license (http://wp7guide.codeplex.com/license)
//===============================================================================


namespace AzureToolkit
{
    using System;
    using System.Collections.Generic;

    public interface IAzureQueue<TMessage> : IInitializer where TMessage : IAzureQueueMessage
    {
        /// <summary>
        /// Clears the queue.
        /// </summary>
        void Clear();
        /// <summary>
        /// Adds the message to the queue.
        /// </summary>
        /// <param name="message">The message.</param>
        void AddMessage(TMessage message);


        /// <summary>
        /// Adds the message async.
        /// </summary>
        /// <param name="message">The message.</param>
        void AddMessageAsync(TMessage message);

        event EventHandler<QueueMessageEventArgs<TMessage>> AddMessageCompleted;

        /// <summary>
        /// Begins the add message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        IAsyncResult BeginAddMessage(TMessage message, AsyncCallback callback, object state);

        /// <summary>
        /// Ends the add message.
        /// </summary>
        /// <param name="asyncResult">The async result.</param>
        void EndAddMessage(IAsyncResult asyncResult);

        /// <summary>
        /// Gets the top message from the queue.
        /// </summary>
        /// <returns>The message object.</returns>
        TMessage GetMessage();
        /// <summary>
        /// Gets the top messages from the queue.
        /// </summary>
        /// <param name="maxMessagesToReturn">The max messages to return.</param>
        /// <returns>The message objects.</returns>
        IList<TMessage> GetMessages(int maxMessagesToReturn);
        /// <summary>
        /// Deletes the message from the queue.
        /// </summary>
        /// <param name="message">The message.</param>
        void DeleteMessage(TMessage message);

        /// <summary>
        /// Deletes the message asynchronously.
        /// </summary>
        /// <param name="message">The message.</param>
        void DeleteMessageAsync(TMessage message);

        void ErrorOutMessage(TMessage message, Exception ex);

        int RetreiveApproximateMessageCount();

    }
}